package nowcoder.meituan;

import java.util.Scanner;

public class TestCode4 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt(); // root
        int[][] tree = new int[n+1][2];
        for(int i = 1; i <= n; i++){
            tree[i][0] = sc.nextInt();
            tree[i][1] = sc.nextInt();
        }
        int[] change = new int[m];
        for(int i = 0; i < m; i++){
            change[i] = sc.nextInt();
        }
        changeIt(change, tree);
        printIt(k, tree);
    }

    private static void changeIt(int[] change, int[][] tree){
        for(int i : change){
            int tmp = tree[i][0];
            tree[i][0] = tree[i][1];
            tree[i][1] = tmp;
        }
    }

    private static void printIt(int k, int[][] tree){
        if(k==0) return;
        printIt(tree[k][0], tree);
        System.out.print(k + " ");
        printIt(tree[k][1], tree);
    }

    private static class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        public TreeNode(int n){
            val = n;
        }
    }
}
